<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/3 0003
 * Time: 17:09
 */
$server = new swoole_websocket_server('192.168.3.221', 8812);

$server->set([
    'enable_static_handler' => true,
    'document_root' => '/data/wwwroot/www/swoole-demo/mooc/data/'
]);

//监听websocket连接事件
$server->on('open', 'onOpen');
function onOpen($server, $request){
    print_r('aaa:'.$request->fd.PHP_EOL);
};

//监听websocket消息事件
$server->on('message', function($server, $frame){
    echo "bbb:receive from {$frame->fd}:{$frame->data}, opcode:{$frame->opcode}, finish:{$frame->finish}\n";
    $server->push($frame->fd, "singwa-push-success:$frame->fd");
});

//监听websocket关闭事件
$server->on('close', function($ser, $fd){
    echo "ccc:client {$fd} closed\n";
});

$server->start();














